from sqlalchemy import Column, Integer, String
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship

from database.models.ControllerPoint import ControllerPoint
from database.models.DatabaseCommon import Base
from database.models.Normal import Normal
from database.models.OptType import OptType


class OperationSet(Base):
    __tablename__ = 'OperationSet'
    id = Column(Integer, primary_key=True, autoincrement=True)
    PointID = Column(Integer, ForeignKey('ControllerPoints.id'))
    point = relationship('ControllerPoint', back_populates='operations')
    OptTypeID = Column(Integer, ForeignKey('OptType.id'))
    opttype = relationship('OptType', back_populates='operations')
    Params = Column(String)
    NormalID = Column(Integer, ForeignKey('Normals.id'))
    normal = relationship('Normal', back_populates='operations')

    def __repr__(self):
        return "<OperationSet (id='%d', OptTypeID ='%d', Params='%s')>" % (
            self.id, self.OptTypeID, self.Params)


ControllerPoint.operations = relationship('OperationSet', order_by=OperationSet.id, back_populates='point')
OptType.operations = relationship('OperationSet', order_by=OperationSet.id, back_populates='opttype')
Normal.operations = relationship('OperationSet', order_by=OperationSet.id, back_populates='normal')
